<!--
描述：教学管理-班级管理-班级添加、编辑
开发人：hqj
开发日期：2018年08月10日
-->
<template lang="pug">
    kalix-dialog.user-add(bizKey="classInfo" ref="kalixBizDialog" v-bind:formModel.sync="formModel" v-bind:targetURL="targetURL" v-bind:editCustom="formModel.cfgKey")
        div.el-form.kalix-form-table(slot="dialogFormSlot")
            el-form-item.s-flex.kalix-form-table-td(label="年级" prop="gradeId" v-bind:rules="rules.gradeId" v-bind:label-width="labelWidth")
                kalix-object-select2(v-model="formModel.gradeId" v-bind:objectsUrl="gradeURL" v-bind:label="'grade'" v-on:objectSelected="gradeSelected")
            el-form-item.s-flex.kalix-form-table-td(label="专业" prop="majorId" v-bind:rules="rules.majorId" v-bind:label-width="labelWidth")
                kalix-object-select2(v-model="formModel.majorId" v-bind:objectsUrl="majorURL" v-bind:label="'cnName'")
            el-form-item.s-flex.kalix-form-table-td(v-if="isEdit" label="班级序号" prop="xh" v-bind:rules="rules.xh" v-bind:label-width="labelWidth")
                el-input(v-model="formModel.xh")
            el-form-item.s-flex.kalix-form-table-td(label="班级名称" prop="name" v-bind:rules="rules.name" v-bind:label-width="labelWidth")
                el-input(v-model="formModel.name")
</template>

<script type="text/ecmascript-6">
    import FormModel from './model'
    import {classInfoURL, gradeURL} from '../../config.toml'

    export default {
        name: 'ClassInfoAdd',
        data() {
            return {
                formModel: Object.assign({}, FormModel),
                rules: {
                    gradeId: [{required: true, type: 'number', message: '请选择年级', trigger: 'change'}],
                    majorId: [{required: true, type: 'number', message: '请选择专业', trigger: 'change'}],
                    name: [{required: true, message: '请输入班级名称', trigger: 'blur'}],
                    xh: [{required: true, message: '请输入2位班级序号', trigger: 'blur'}]
                },
                targetURL: classInfoURL,
                gradeURL: gradeURL,
                majorURL: '',
                isEdit: false,
                labelWidth: '110px'
            }
        },
        components: {},
        mounted() {
            setTimeout(() => {
                if (this.formModel.id && this.formModel.id > 0) {
                    this.isEdit = true
                }
            }, 20)
        },
        methods: {
            gradeSelected(grade) {
                this.formModel.majorId = null
                if (grade && !this.$M_IsEmptyObject(grade)) {
                    this.majorURL = '/camel/rest/grades/' + grade.id + '/majorinfos'
                } else {
                    this.majorURL = ''
                }
            }
        }
    }
</script>

<style scoped>
</style>
